<?php

namespace App\Providers;

use App\Models\Menu;
use Illuminate\Support\ServiceProvider;
use Illuminate\View\View;

class ComposerServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        view()->composer('layouts.app',function (View $view){
//            $menu = \Cache::remember(
//                'menu', 120, function () {
//                return Menu::query()->where('parent_id', 0)->with('sub')->oldest('sort')
//                    ->get()->toArray();
//            });
            $menu = Menu::query()->where('parent_id', 0)->with('sub')->oldest('sort')
                ->get()->toArray();
            return $view->with('menu',$menu);
        });
    }

    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}
